home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / ttyfix.arc / TTYFIX.C < prev    next >
Text File  |  1990-11-05  |  1KB  |  55 lines

  1. /* ttyfix.  Copyright (c) 1990 by David M. Hayden
  2.  * All rights Reserved.
  3.  *
  4.  * This program may be used and distributed at will, provided that it is
  5.  * distributed with this notice and the above copyright notice.  You may not
  6.  * sell this program for profit without the written permission of the author.
  7.  
  8.  * This program is a simple filter to fix some of the problems with the
  9.  * windows 3.0 "Generic / Text Only" printer driver.  The program fixes the
  10.  * following two bugs:
  11.  *
  12.  *    1: When printing justified paragraphs, the driver prints zillions
  13.  *       of one-character lines.  This collapes them into one line
  14.  *    2: The driver ends lines with a line-feed/carriage return pair
  15.  *       instead of the other way around.
  16.  *
  17.  */
  18.  
  19. #include <stdio.h>
  20.  
  21. char line[200];    /* holds input line of text */
  22.  
  23. main(int argc, char **argv)
  24.     {
  25.     int index = 0, i;
  26.     char ch;
  27.     FILE *fp;
  28.  
  29.     /* open the input file */
  30.     if (argc>=2) fp = freopen(argv[1], "rb", stdin);
  31.     else fp = stdin;
  32.  
  33.     for (i=0; i<200; i++) line[i] = ' ';
  34.  
  35.     while (fread(&ch, 1, 1, fp) > 0) {
  36.     switch(ch) {
  37.         case '\r':
  38.         index = 0;
  39.         break;
  40.         case '\n':
  41.         line[index]=0;
  42.         puts(line);
  43.         for(i=0; i<200; i++) line[i] = ' ';
  44.         index = 0;
  45.         break;
  46.  
  47.         default:
  48.         if (line[index] == ' ' || line[index] == '_') {
  49.             line[index] = ch;
  50.             }
  51.         index++;
  52.         break;
  53.         }
  54.     }
  55.     }